/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Base for creating a custom VGUI class; remove the functions you don't use.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
NoticeSpeed = 1	//Bigger = faster


local PANEL = {}

function PANEL:Init()
	//Create controls here
	print( "SCROLLING NOTICE SPAWNED" )
	
	self.MESS = "No Text"
	self.MX = ScrW()
	
	local Message = vgui.Create( "DLabel", self )
		Message:SetFont( "CloseCaption_BoldItalic" )
		Message:SetText( self.MESS )
		Message:SetPos( self.MX, 0 )
		Message:AlignBottom( 2 )
		
		self.MESSAGE = Message

end

function PANEL:PerformLayout()
	
	// Let's make sure we perform the layout of the class this panel is based on here as well.
	self.BaseClass.PerformLayout( self )
	
	self:SetSize( ScrW(), 25 )

end

function PANEL:Paint()
	//Do Painting here
	
	self.BaseClass.Paint( self )
	
	draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color( 120, 120, 120, 255 ) )
	draw.RoundedBox( 0, 2, 2, self:GetWide() - 4, self:GetTall() - 4, Color( 10, 10, 10, 255 ) )

end

function PANEL:PaintOver()

	//Paint over self and child elements here.

end

function PANEL:Think()
	//Think stuff here
	
	self.MX = self.MX - NoticeSpeed
	self.MESSAGE:SetText( self.MESS )
	self.MESSAGE:SizeToContents()
	local SX,SY = self.MESSAGE:GetPos()
	self.MESSAGE:SetPos( self.MX, SY )
	
	if self.MX <= -(self.MESSAGE:GetWide()) then
		self:Remove()
	end

end

function PANEL:OnCursorEntered()

	//Do stuff when the cursor enters the panel

end

function PANEL:OnCursorExited()

	//Do Stuff when the cursor leaves the panel

end

function PANEL:OnMouseWheeled()

	//Do stuff when you wheel the mouse on this panel

end

function PANEL:OnMousePressed()

	//Do stuff when you press the mouse on this panel

end

function PANEL:OnMouseReleased()

	//Do stuff when you release the mouse on this panel

end

function PANEL:OnKeyCodePressed()

	//Do stuff when using keys from the keyboard on this panel. This hook uses the keycode enumerations
	//http://wiki.garrysmod.com/?title=P.OnKeyCodePressed	For more information

end

function PANEL:ActionSignal()

	//This is called on the parent frame when a child VGUI element is used. The key corresponds to what is set by Panel.SetCommand.
	//From the wiki
	
end

function PANEL:OnCursorMoved()

	//From the wiki
	//Called whenever the the mouse is moved within the panel.

end

function PANEL:DoClick()

	//For button type panels, use this. Called when you click the button.

end


//Register syntax - Desired element name, Panel to use, base class of the new element.
vgui.Register( "ScrollingNotice", PANEL, "DPanel" )

function NoticeHook( um )
	local NOTICE = vgui.Create( "ScrollingNotice" )
		NOTICE.MESS = um:ReadString()
end
usermessage.Hook("NoticeMSG", NoticeHook)